import { ILv70DramaStepCommand } from "../interfaces/ILv70DramaStepCommand";
import { TDrama } from "../../../../../Message/Db/Tables/TDrama";
import { Global } from "../../../../../com/gengine/global/Global";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { LayerManager } from "../../../manager/LayerManager";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { Lv70NpcTalkLeftDownMask } from "./npctalk/Lv70NpcTalkLeftDownMask";
import { ObjCreate } from "../../common/ObjCreate";
import { FontUtil } from "../../../../common/font/FontUtil";
type int = number;
//class Lv70OpDownLeftShowText
    
    export  class Lv70OpDownLeftShowText implements ILv70DramaStepCommand
    {
        constructor()
        {
            
            this.initView();
            return;
        }

        public call(arg1: TDrama, arg2: Function=null): void
        {
            var loc6=null;
            var loc1=arg1.text;
            if (loc1 == null || loc1 == "" || Global.stage.stageHeight <= 400) 
            {
                if (arg2 != null) 
                {
                    arg2.apply();
                }
                return;
            }
            this._onEnd = arg2;
            var loc2;
            var loc3=(loc2 = Global.stage.stageHeight - 300) / (this.Size + this.LeadingY);
            var loc4=loc1.length / loc3;
            if (loc1.length % loc3 != 0) 
            {
                ++loc4;
            }
            var loc5=0;
            while (loc5 < this.MaxLineNum) 
            {
                (loc6 = this._txts[loc5] as GTextFiled).visible = true;
                if (loc5 >= loc4) 
                {
                    loc6.visible = false;
                }
                else 
                {
                    loc6.height = loc2 + 20;
                    loc6.htmlText = loc1.substr(loc5 * loc3, loc3);
                }
                ++loc5;
            }
            this._sp.x = 3 * Global.stage.stageWidth / 4 + loc4 * (this.Size + this.LeadingX + 1) / 2 - this._sp.width;
            this._sp.y = 150;
            if (this._sp.parent == null) 
            {
                LayerManager.highestLayer.addChild(this._sp);
            }
            this._mask.reInit(loc4, this.Size, loc2, this.LeadingX, this.onShowEnd);
            Global.stage.addEventListener(flash.events.MouseEvent.CLICK, this.clickSkipHandler);
            return;
        }

        /* internal  */clickSkipHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._mask.skip();
            return;
        }

        /* internal  */onShowEnd(): void
        {
            Global.stage.removeEventListener(flash.events.MouseEvent.CLICK, this.clickSkipHandler);
            DisplayUtil.removeMe(this._sp);
            if (this._onEnd != null) 
            {
                this._onEnd.apply();
            }
            return;
        }

        public cancel(arg1: TDrama, arg2: Function=null): void
        {
            return;
        }

        public dispose(): void
        {
            return;
        }

        /* internal  */initView(): void
        {
            var loc2=null;
            var loc3=null;
            this._sp = new Object /* flash.display.Sprite */();
            this._mask = new Lv70NpcTalkLeftDownMask();
            this._sp.addChild(this._mask);
            this._mask.x = (this.Size + this.LeadingX) * (this.MaxLineNum - 1);
            this._sp.mask = this._mask;
            this._txts = [];
            var loc1=0;
            while (loc1 < this.MaxLineNum) 
            {
                loc2 = ObjCreate.createGTextField("", 0, 0, this.Size + 4, 300, this._sp);
                loc3 = loc2.defaultTextFormat;
                loc3.leading = this.LeadingY;
                loc3.size = this.Size;
                loc3.color = 16772863;
                loc3.font = FontUtil.xingkaiName;
                loc2.multiline = true;
                loc2.wordWrap = true;
                loc2.defaultTextFormat = loc3;
                loc2.x = ((this.MaxLineNum - 1) - loc1) * (this.LeadingX + this.Size);
                loc2.y = 0;
                loc2.mouseEnabled = false;
                loc2.mouseWheelEnabled = false;
                this._txts.push(loc2);
                ++loc1;
            }
            return;
        }

        /* internal */ /* const */Size: int=28;

        /* internal */ /* const */LeadingX: int=28;

        /* internal */ /* const */LeadingY: int=6;

        /* internal */ /* const */MaxLineNum: int=20;

        /* internal */ /* var */_sp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_txts: Array<any>;

        /* internal */ /* var */_mask: Lv70NpcTalkLeftDownMask;

        /* internal */ /* var */_onEnd: Function;

        /* internal */ /* var */LineHeight: int=380;
    }
